// socket服务中通过socket.client.request.url可获取如下格式的字符串:
// /socket.io/?userId=%E9%9D%B3%E8%8D%A3%E8%BE%BE&roomId=%E6%B5%8B%E8%AF%95&EIO=4&transport=websocket
// 也就是说/socket.io/?与&EIO=4&transport=websocket之间为客户端连接io服务时的query参数,并且已经经过encode
// 获取url中queryName对应的value
function getUrlParams(url, queryName) {
  const queryStr = url.split('?')[1];
  const decodeQueryStr = decodeURIComponent(queryStr);
  const queryList = decodeQueryStr.split('&');
  for(let i = 0; i < queryList.length; i++) {
    const [key, value] = queryList[i].split('=');
    if(key === queryName) return value;
  }
  return null;
}

module.exports = {
  getUrlParams
}